local huiming = fk.CreateSkill{
  name = "tsp__huiming"
}

Fk:loadTranslationTable{
  ["tsp__huiming"] = "隳命",
  [":tsp__huiming"] = "你成为其他角色【杀】或普通锦囊牌的唯一目标后，你可以弃置你至多三张手牌，"..
    "然后弃置其等量张手牌，令此牌改为结算等量次。",

  ["#tsp__huiming"] = "隳命：你可以弃置至多三张手牌发动“隳命”",
  ["#tsp__huiming_discard"] = "隳命：弃置 %dest 的 %arg 张手牌",
}

huiming:addEffect(fk.TargetConfirmed, {
  can_trigger = function (self, event, target, player, data)
    return player == target and player:hasSkill(self) and #data:getAllTargets() == 1
      and (data.card.trueName == "slash" or data.card:isCommonTrick()) and data.from ~= player
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local cards1 = room:askToDiscard(player, {
      min_num = 1,
      max_num = 3,
      cancelable = true, 
      skill_name = huiming.name,
      skip = true,
      include_equip = false,
      prompt = "#tsp__huiming",
    })
    if #cards1 == 0 then return end
    local cards2 = room:askToChooseCards(player, {
      flag = "h",
      min = #cards1,
      max = #cards1,
      skill_name = huiming.name, 
      target = data.from,
      prompt = "#tsp__huiming_discard::"..data.from.id..":"..#cards1,
    })
    event:setCostData(self, {
      cards1 = cards1,
      cards2 = cards2,
    })
    return true
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local cost_data = event:getCostData(self)
    local cards1 = cost_data.cards1
    local cards2 = cost_data.cards2
    room:throwCard(cards1, huiming.name, player, player)
    room:throwCard(cards2, huiming.name, data.from, player)
    data.use.additionalEffect = #cards1 - 1
  end
})

return huiming